package com.common.bean;


import org.json.JSONException;
import org.json.JSONObject;

import com.common.allCommon.JSONObjecthelper;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;



/**
 * 养成数据结构体
 * <br>Created 2014-5-7 下午8:31:25
 * @version  
 * @author   linsj		
 *
 * @see 	 
 */
public class NourishData extends AppMsgData implements Parcelable {
	/**养成消息推送原因码　KEY名*/
	public static String KEY_CHANGE_TYPE = "chng_type";	
	/**旧经验值 key名*/
	public static String KEY_OLD_EXP = "old_exp";
	/**新经验值 key名*/
	public static String KEY_NEW_EXP = "new_exp";
	/**旧等级 key名*/
	public static String KEY_OLD_GRADE = "old_grade";
	/**新等级 key名*/
	public static String KEY_NEW_GRADE = "new_grade";
	/**旧威望值 key名*/
	public static String KEY_OLD_PRESTIGE = "old_prestige";
	/**新威望值 key名*/
	public static String KEY_NEW_PRESTIGE = "new_prestige";
	/**旧威望称号 key名*/
	public static String KEY_OLD_PRESTIGE_TITLE = "old_prestige_title";
	/**新威望称号 key名*/
	public static String KEY_NEW_PRESTIGE_TITLE = "new_prestige_title";
	
	/**由升级引起的推送*/
	public static final int CHNG_TYPE_GRADE = 1;
	/**由威望值增加引起的推送*/
	public static final int CHNG_TYPE_PRESTIGE = 2;
	/**由升级且威望值增加引起的推送*/
	public static final int CHNG_TYPE_GRADE_PRESTIGE = 3;
	
	/**旧的经验值*/
	public long lOldExp = 0;
	/**引起养成消息推送原因代码*/
	public int iChangeType = 0;
	/**新的经验值*/
	public long lNewExp = 0;
	/**旧等级*/
	public long lOldGrade = 0;
	/**新等级*/
	public long lNewGrade = 0;
	/**旧威望值*/
	public long lOldPrestige = 0;
	/**新威望值*/
	public long lNewPrestige = 0;
	/**旧威望称号*/
	public String strOldPrestigeTitle = "";
	/**新威望称号*/
	public String strNewPrestigeTitle = "";
	
	
	
	/**
	 * Creates a new instance of NourishData.
	 *
	 */
	public NourishData(){
		
	}
	
	public static final Parcelable.Creator<NourishData> CREATOR = new Parcelable.Creator<NourishData>() {
		public NourishData createFromParcel(Parcel in) {
			return new NourishData(in);
		}

		public NourishData[] newArray(int size) {
			return new NourishData[size];
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}
	
	
	/**
	 * 序列化入
	 * <br>Created 2014-5-7 下午8:33:06
	 * @param in 序列化入
	 */
	private NourishData(Parcel in) {
		super.parcelInData(in);
		iChangeType = in.readInt();
		lOldExp = in.readLong();
		lNewExp = in.readLong();
		lOldGrade = in.readLong();
		lNewGrade = in.readLong();
		lOldPrestige = in.readLong();
		lNewPrestige = in.readLong();
		strOldPrestigeTitle = in.readString();
		strNewPrestigeTitle = in.readString();
	}
	
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		super.writeToParcel(dest, flags);
		dest.writeInt(iChangeType);
		dest.writeLong(lOldExp);
		dest.writeLong(lNewExp);
		dest.writeLong(lOldGrade);
		dest.writeLong(lNewGrade);
		dest.writeLong(lOldPrestige);
		dest.writeLong(lNewPrestige);
		dest.writeString(strOldPrestigeTitle);
		dest.writeString(strNewPrestigeTitle);
	}

	@Override
	public void parseJson(String strJson) {
		if(TextUtils.isEmpty(strJson)){
			return;
		}	
		
		JSONObject jsonData = null;
		try {
			jsonData = new JSONObject(strJson);
		} catch (JSONException e) {
			return;
		}
		
		lMsgID = JSONObjecthelper.getInt(jsonData, "msg_id");
		iChangeType = JSONObjecthelper.getInt(jsonData, "chng_type");
		lOldExp = JSONObjecthelper.getLong(jsonData, "old_exp");
		lNewExp = JSONObjecthelper.getLong(jsonData, "new_exp");
		lOldGrade = JSONObjecthelper.getLong(jsonData, "old_grade");
		lNewGrade = JSONObjecthelper.getLong(jsonData, "new_grade");
		lOldPrestige = JSONObjecthelper.getLong(jsonData, "old_prestige");
		lNewPrestige = JSONObjecthelper.getLong(jsonData, "new_prestige");
		strOldPrestigeTitle = JSONObjecthelper.getString(jsonData, "old_prestige_title");
		strNewPrestigeTitle = JSONObjecthelper.getString(jsonData, "new_prestige_title");
	}
}
